﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PhatPhucLoc.dao;

namespace PhatPhucLoc.view
{
    public partial class FormHangHoa : Form
    {
        public FormHangHoa()
        {
            InitializeComponent();
            FormHangHoaLoad();
            
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormHangHoa formHangHoa = this;
            FormThemHangHoa formThemHangHoa = new FormThemHangHoa(ref formHangHoa);
            formThemHangHoa.ShowDialog();
        }

        public void FormHangHoaLoad()
        {
            DataTable dt = HangHoaDAO.GetAll();
            dgvHangHoa.DataSource = dt;
        }


        private void FormHangHoa_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if (e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void FormHangHoa_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormHangHoa_KeyDown);
        }

        private void dgvHangHoa_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormHangHoa frm = this;
            HangHoaModel HangHoaModel = new HangHoaModel();
            HangHoaModel.Id = dgvHangHoa.CurrentRow.Cells["id"].Value.ToString();
            HangHoaModel.Ten = dgvHangHoa.CurrentRow.Cells["TenHH"].Value.ToString();
            HangHoaModel.MaHang = dgvHangHoa.CurrentRow.Cells["MaHang"].Value.ToString();
            HangHoaModel.MaNhomHang = dgvHangHoa.CurrentRow.Cells["MaNhomHang"].Value.ToString();
            HangHoaModel.GiaNhap = dgvHangHoa.CurrentRow.Cells["GiaNhap"].Value.ToString();
            HangHoaModel.GhiChu = dgvHangHoa.CurrentRow.Cells["GhiChu"].Value.ToString();
            FormThemHangHoa formThemNhomHang = new FormThemHangHoa(HangHoaModel,ref frm );
            formThemNhomHang.ShowDialog();
        }

      
    }
}
